version 18.0               // version control
set processors 8           // to ensure replicability across different numbers of cores
clear all                  // clear existing data
macro drop _all            // and macros, clean slate
set seed 20220801          // set seed

*-------------------------------------------------------
* project: daylight saving time (dst)
*-------------------------------------------------------

local pgm  "dst-data03_for_estimation_central_mountain" // file name
local who  "Muzhe Yang"                                 // author
local dte  "2022-08-01"                                 // created date
local dte2 "`c(current_date)'"                          // last run date
local tag  "`pgm'.do, created by `who' on `dte', last run on `dte2'"

capture log close
log using "code\management\\`pgm'.txt", replace text
display "`tag'"

use          "data_clean\places\dst-data01_places_2020_release_central_mountain_clean", clear
append using "data_clean\places\dst-data01_places_2021_release_central_mountain_clean"
sort TractFIPS wave
drop if CountyFIPS == "06065" & time_zone == "Mountain" // 06065 is Riverside County, CA, which is in Pacific Time Zone.
gen GEOID = TractFIPS
compare GEOID TractFIPS
merge m:1 GEOID using "data_clean\acs\dst-data02_acs_combine"
drop if _merge == 2
drop GEOID State County _merge
merge m:1 CountyFIPS using "data_clean\solar\dst-data02_solar_county_avg"
drop if _merge == 2
drop _merge
order county_lon county_lat, before(centroid_lon)

replace dist_to_border = dist_to_border*0.000621371 // https://www.google.com/search?client=firefox-b-1-d&q=unit+converter (meter converted to mile)
label variable dist_to_border "distance between a census tract's centroid and the time zone border (in miles)"

sort TractFIPS wave
codebook, compact
compress
save "data_clean\\`pgm'.dta", replace 

log close
exit